package com.moresir.validatetools.config;

import com.moresir.validatetools.common.response.ResponseEnum;
import com.moresir.validatetools.exceptions.BusinessException;
import com.moresir.validatetools.impl.RulesMessages;

import java.util.ArrayList;
import java.util.Optional;

public class LanguageList extends ArrayList<RulesMessages> {

    public LanguageList() {
        add(new RMessageEn());
    }

    public RulesMessages getByLanguage(String lang)
    {
        Optional<RulesMessages> first = stream().filter(e -> e.getLang().equals(lang)).findFirst();
        if (first.isPresent())
            return first.get();
        throw new BusinessException(ResponseEnum.VALIDATE_RULE_LANGUAGE_CONFIG_NOT_EXIST, lang);
    }
}
